package com.dai.zhenfujin.http;

import com.dai.zhenfujin.utils.UIUtils;
import com.google.gson.internal.$Gson$Types;
import com.hyphenate.exceptions.HyphenateException;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 *
 */
public abstract class CallBack<T> {
    public Type type;

    public CallBack() {
          type = getSuperclassTypeParameter(getClass());
    }

    public static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    public abstract void onSuccess(T result) throws HyphenateException;

    public void onFailure(int errorType,String message) {
        if (errorType == 4 ){
            UIUtils.showToastSafe("服务器连接超时");
        }
       // Toast.makeText(BaseApplication.getContext(),"服务器异常，请稍后再试", Toast.LENGTH_SHORT).show();
        //System.out.println("errorType = [" + errorType + "], message = [" + message + "]");
    }
}

